package com.knowif.backend.service;

import com.github.pagehelper.PageHelper;
import com.knowif.pojo.Product;
import com.knowif.pojo.ProductExample;
import com.knowif.service.Product_service;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class ProductService {

    @Autowired
    private Product_service product_service;

    /**
     * 条件查询product
     * @param productExample
     * @return
     */
    public List<Product> selectProduct(ProductExample productExample){
        return product_service.selectProduct(productExample);
    }

    /**
     * 条件查询product
     * @param productExample
     * @param pageable 是否需要分页
     * @return
     */
    public List<Product> selectProduct(ProductExample productExample, boolean pageable){
        if(! pageable){
            PageHelper.clearPage();
        }
        return product_service.selectProduct(productExample);
    }


    /**
     * 保存product
     * @return
     */
    public boolean saveProduct(Product product){
        int i = product_service.saveProduct(product);
        if(i == 0){
            return false;
        }
        return true;
    }

    /**
     * 保存product
     * @return
     */
    public boolean updateProductNotNull(Product product){
        int i = product_service.updateProductNotNull(product);
        if(i == 0){
            return false;
        }
        return true;
    }

    /**
     * 保存product
     * @return
     */
    public boolean updateProduct(Product product){
        int i = product_service.updateProduct(product);
        if(i == 0){
            return false;
        }
        return true;
    }

    /**
     * 删除product
     * @return
     */
    public boolean deleteProduct(int productId){
        int i = product_service.deleteProduct(productId);
        if(i == 0){
            return false;
        }
        return true;
    }

    /**
     * 主键id选择product
     * @return
     */
    public Product selectByPrimaryKey(int productId){
        return product_service.selectByPrimaryKey(productId);
    }


}
